package com.shopx.auth.controller;

import com.shopx.auth.bean.SysUrl;
import com.shopx.auth.model.SysUrlModel;
import com.shopx.auth.service.ISysUrlService;
import com.shopx.base.anno.RepearSubmitChkAnno;
import com.shopx.base.anno.ShopxParamAnno;
import com.shopx.base.controller.BaseController;
import com.shopx.base.dto.Result;
import com.shopx.base.exception.ShopxException;
import com.shopx.base.utils.ResultUtil;
import com.shopx.cmm.DTO.PageDTO;
import com.shopx.core.common.CommonConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lituo
 * @className: SysConfigController
 * @description: 菜单
 * @date 2021/12/5 12:04 PM
 */
@RestController
@Slf4j
@RequestMapping(value = "/sysUrl")
public class SysUrlController extends BaseController {

  @Autowired
  private ISysUrlService sysUrlService;

  @RequestMapping(value = "/queryPageList")
  @ShopxParamAnno
  public Result<?> queryPageList(@RequestBody SysUrlModel sysUrl) throws ShopxException {
    PageDTO<SysUrlModel> pageDTO = sysUrlService.getListPage(sysUrl);
    return ResultUtil.ok(pageDTO);
  }

  @RequestMapping(value = "/insertOne")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  @ShopxParamAnno
  public Result<?> insertOne(@RequestBody SysUrl sysUrl) throws ShopxException {
    int result = sysUrlService.insertSelective(sysUrl);
    return ResultUtil.ok(result);
  }

  @RequestMapping(value = "/updateOne")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  @ShopxParamAnno
  public Result<?> updateOne(@RequestBody SysUrl sysUrl) throws ShopxException {
    int result = sysUrlService.updateByPrimaryKeySelective(sysUrl);
    return ResultUtil.ok(result);
  }

  @RequestMapping(value = "/queryOneByPrimaryKey")
  @ShopxParamAnno
  public Result<?> queryOneByPrimaryKey(@RequestBody SysUrl sysUrl) throws ShopxException {
    SysUrlModel result = sysUrlService.selectByPrimaryKey(sysUrl);
    return ResultUtil.ok(result);
  }

  @RequestMapping(value = "/getUrlByUserId")
  @ShopxParamAnno
  public Result<?> getUrlByUserId() throws ShopxException {
    List<SysUrlModel> list = sysUrlService.getCurUserUrl();
    return ResultUtil.ok(list);
  }

  @RequestMapping(value = "/queryUrlNodeList")
  @ShopxParamAnno
  public Result<?> queryUrlNodeList(String parUrlId) {
    String s = sysUrlService.queryUrlNodeList(parUrlId);
    return ResultUtil.ok(s);
  }

  @RequestMapping(value = "/queryEditUrlNodeList")
  @ShopxParamAnno
  public Result<?> queryEditUrlNodeList(@RequestBody  SysUrlModel sysUrlModel) {
    String s = sysUrlService.queryEditUrlNodeList(sysUrlModel);
    return ResultUtil.ok(s);
  }


  @RequestMapping(value = "/deleteChecked")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  @ShopxParamAnno
  public Result<?> deleteChecked(@RequestBody SysUrl sysUrl) throws ShopxException {
    int result = sysUrlService.deleteByPrimaryKey(sysUrl);
    return ResultUtil.ok(result);
  }

  @RequestMapping(value = "/deleteChkIds")
  @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
  @ShopxParamAnno
  public Result<?> deleteChkIds(@RequestBody SysUrlModel sysUrl) throws ShopxException {
    sysUrlService.deleteChkIds(sysUrl);
    return ResultUtil.ok(true);
  }
}

